package comfive.dao.impl;

import comfive.dao.UserDao;
import comfour.user.User;
import comfour.util.BaseJdbc;

import java.sql.ResultSet;

public class UserDaoImpl  implements UserDao {

    @Override
    public boolean login(String uname, String password) {
        String sql="select * from student where StudentName=? and loginPwd=?";
        Object[] objects = new Object[2];
        objects[0]=uname;
        objects[1]=password;
        ResultSet baseSelect = BaseJdbc.getBaseSelect(sql, objects);
        User user=null;
        try {
            while (baseSelect.next()){
                user= new User();
                user.setId(baseSelect.getInt("studentNo"));
                user.setUname(baseSelect.getString("studentName"));
                user.setuPassWord(baseSelect.getString("loginpwd"));
            }
        }catch (Exception e){
            e.printStackTrace();

        }
        if(user!=null){
            return true;
        }
        return false;
    }

    @Override
    public boolean addUser(User user) {
        String sql="insert into student(studentname,loginpwd)value(?,?)";
        Object[] objects = new Object[2];
        objects[0]=user.getUname();
        objects[1]=user.getuPassWord();
        int count = BaseJdbc.BaseUpdate(sql, objects);
        if(count>0){
            return  true;
        }
        return false;
    }
}
